import React from 'react';
import { Toast, } from 'antd-mobile';

export default class Index extends React.Component {
    constructor(props){
        super(props)
        this.state={
            rmb: 0,
            bl: props.match.params.bl,
            data: [],
            money: 0,
        }
    }
	componentDidMount(){
		document.title = '提现'
        global.Ajax.hhtc_request('tx/infos',{}).then(data=>{
			if(data.code===1){
				this.setState(data.data)
			}
		})
    }
    sub(){
        if(this.state.money<=0){
            return Toast.fail('提现金额必须大于零!',1)
        }
        Toast.loading()
        global.Ajax.hhtc_request('tx/tx',{money: this.state.money}).then(data=>{
            Toast.hide()
			if(data.code===1){
				Toast.success(data.msg,1,()=>{
                    window.location.reload()
                })
			}else{
                Toast.fail(data.msg,1)
            }
		})
    }
	render(){
		return(
			<div className='set_box'>
                <div className='select_box' onClick={()=>{this.props.history.push('/page/home/user/paytype/'+this.state.data.id)}}>
                    {this.state.data.account!=undefined?<React.Fragment>
                        {this.state.data.type===2?<img alt='' src={require('../../imgs/alipay.png')} className='icon' />:<img alt='' src={require('../../imgs/card.png')} className='icon' />}
                        <p>{this.state.data.type===2?'支付宝':this.state.data.bank_name}&emsp;****{this.state.data.account.substring(this.state.data.account.length-4)}</p>
                    </React.Fragment>:<p>请选择</p>}
                    <img alt='' src={require('../../imgs/r2.png')} className='r2' />
                </div>
                <p className='p1'>提现金额</p>
                <div className='inptbox'>
                    <span>￥</span>
                    <input placeholder='0.00' type='number' onChange={(e)=>{
                        this.setState({
                            money: e.target.value,
                        })
                    }} />
                </div>
                <span className='kye'>可用积分{this.state.rmb*1}，1积分可提现{this.state.bl}元</span>
                <p className='btn' onClick={this.sub.bind(this)}>预计24小时内到账，确认提现</p>
			</div>
		)
	}
}
